springboot缓存注解:为 SpringBoot 项目接入基于 Redis 的 @CacheResult

springboot缓存注解(@user_faca7523/springboot-cache)面向已有 springboot-init 骨架的 SpringBoot 项目,通过脚本注入 @CacheResult、AOP 切面、Redis 配置与 Hutool/AOP 依赖。支持 keyPrefix、普通 key、SpEL key 与默认 key 策略,可配置 TTL;含 null 值标记、缓存失败不影响业务及 Jackson 序列化。本文说明注解参数、生成文件、cache_annotation.py 用法与适用注意。

Read More
FastAPI State Management: Simple Implementation of Global Variables and Caching

In FastAPI, two common approaches for state management are global variables and caching. Global variables are the simplest way to share state, usable directly in single-process environments but requiring asyncio.Lock to prevent race conditions in multi-request scenarios. Their limitations include process isolation issues, memory dependency, and data loss risks. Caching is more efficient and categorized into three types: in-memory caching (using dictionaries or the cachetools library, supporting LRU/TTL strategies), and distributed caching (e.g., Redis, suitable for cross-service sharing and persistence). Comparison: Global variables suit single-process, simple scenarios, while caching is ideal for high-frequency access, distributed systems, or data requiring persistence. Practical recommendations: Use global variables or cachetools in development, and distributed caches like Redis in production to avoid cross-process issues with global variables.

Read More